<?php
if(empty($_POST['name'])){
    skip("$_SERVER[REQUEST_URI]",'error','用户名不能为空！');
}
if(mb_strlen($_POST['name'])>32){
    skip("$_SERVER[REQUEST_URI]",'error','用户名不能超过32个字符！');
}
if(isset($_POST['confirm_pw'])){
    if($_POST['pw']!=$_POST['confirm_pw']){
        skip("$_SERVER[REQUEST_URI]",'error','两次输入的密码不一致！');
    }
    if(mb_strlen($_POST['pw'])<6){
        skip("$_SERVER[REQUEST_URI]",'error','密码长度不能少于6位！');
    }
}
if(strtolower($_POST['vcode'])!=strtolower($_SESSION['vcode'])){
    skip("$_SERVER[REQUEST_URI]",'error','验证码输入有误！');
}
if(isset($_POST['time'])){
    if(empty($_POST['time'])||!is_numeric($_POST['time'])||$_POST['time']>2592000){
        $_POST['time']=2592000;
    }
}
switch($checkflag){
    case 'register':
         $query="select *from member where name='{$_POST['name']}'";
         $result=execute($link,$query);
         if(mysqli_num_rows($result)){
             skip("$_SERVER[REQUEST_URI]",'error','该用户名已存在！');
         }
         break;
    case 'login':
        $query="select *from member where name='{$_POST['name']}' and pw=md5('{$_POST['pw']}')";
        $result=execute($link,$query);
        if(mysqli_num_rows($result)==1){
            setcookie('member[name]',$_POST['name'],time()+ $_POST['time']);
            setcookie('member[pw]',sha1(md5($_POST['pw'])),time()+ $_POST['time']);
            skip("{$_GET['url']}",'ok','登陆成功！');
        }else{
            skip("$_SERVER[REQUEST_URI]",'error','用户名或密码有误，请重新登陆！');
        }
}


?>